package ru.papergames.common.netutils;

import ru.papergames.common.form.AbstractPlayerForm;
import ru.papergames.common.form.NpcPlayerForm;
import ru.papergames.common.form.PcPlayerForm;

import java.nio.ByteBuffer;

/**
 * User: troshanin
 * Date: 15.01.2011
 * Time: 0:50:55
 */
public class ModelReaderUtils extends BaseBufferUtils {

    public static AbstractPlayerForm readPlayerFromBuffer(ByteBuffer buffer) {
        AbstractPlayerForm player;
        boolean isPc = readBool(buffer);
        player = isPc ? new PcPlayerForm() : new NpcPlayerForm();
        player.setId(readLong(buffer));
        player.setUsername(readString(buffer));
        player.setLevel(readShort(buffer));

        return player;
    }
}
